int led1=13;
int led2=12;
int led3=10;
int led4=9;
int c1=0,c2=0,c3=0,c4=0;
void setup(){         
  Serial.begin(9600);
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  pinMode(led3,OUTPUT);
  pinMode(led4,OUTPUT);
  digitalWrite(led1,LOW);
  digitalWrite(led2,LOW);
  digitalWrite(led3,LOW);
  digitalWrite(led4,LOW);
}
int valor;
void loop(){
  if(Serial.available())
  {
  valor=Serial.read();
  }
    if( valor=='a'){
      if(c1==1){digitalWrite(led1,HIGH);}
      else{digitalWrite(led1,LOW);}
      c1++;if(c1==2){c1=0;}
    }
    if( valor=='b'){
      if(c2==1){digitalWrite(led2,HIGH);}
      else{digitalWrite(led2,LOW);}
      c2++;if(c2==2){c2=0;}
     
    }
    if( valor=='c'){
      if(c3==1){digitalWrite(led3,HIGH);}
      else{digitalWrite(led3,LOW);}
      c3++;if(c3==2){c3=0;
       delay(1);  
     Serial.write ('A');
      delay(1);  
       
 }
    }
    if( valor=='d'){
      if(c4==1){digitalWrite(led4,HIGH);}
      else{digitalWrite(led4,LOW);}
      c4++;if(c4==2){c4=0;
  delay(1);  
     Serial.write ('B');
      delay(1);      
  
}
    }
    if( valor=='h'){
      digitalWrite(led1,HIGH);
      digitalWrite(led2,HIGH);
      digitalWrite(led3,HIGH);
      digitalWrite(led4,HIGH);  
    }
  if(c1>255){c1=0;}
  if(c2>255){c2=0;}
  if(c3>255){c3=0;}
  if(c4>255){c4=0;}
  valor=0;
}
